import Vue from 'vue'
import Router from 'vue-router'
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading
/* layout */
import Layout from '../views/layout/Layout'

const _import = require('./_import_' + process.env.NODE_ENV)
Vue.use(Router)

// 所有权限通用路由表
// 如首页和登陆页和一些不用权限的公用页面
export const constantRouterMap = [
  {path: '/login', component: _import('login/index'), hidden: true},
  {path: '/404', component: _import('404'), hidden: true},
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    hidden: true,
    children: [{
      path: 'dashboard', component: _import('dashboard/index')
    }]
  },
  {
    path: '/screen',
    name: 'screen',
    meta: {title: '大屏展示', icon: 'tree'},
    component:() => import('../views/screen/Index.vue'),
    children:[
      {
        path: 'technology',
        name: 'technology',
        meta: {title: '技术动态', icon: 'tree'},
        component:() => import('../views/screen/pages/Technology.vue')
      },
      {
        path: 'organization',
        name: 'organization',
        meta: {title: '机构动态', icon: 'tree'},
        component:() => import('../views/screen/pages/Organization.vue')
      },
      {
        path: 'expert',
        name: 'expertpage',
        meta: {title: '专家动态', icon: 'tree'},
        component:() => import('../views/screen/pages/Expert.vue')
      }
    ]
  },
]

// 实例化vue的时候只挂载constantRouter
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})


//异步挂载的路由
//动态需要根据权限加载的路由表 

//这里我们根据 vue-router官方推荐 的方法通过meta标签来标示改页面能访问的权限有哪些。如meta: { role: ['admin','super_editor'] }表示该页面只有admin和超级编辑才能有资格进入。
export const asyncRouterMap = [
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: '',
        component: _import('dashboard/index'),
        meta: {title: '首页', icon: 'tree'},
        menu: 'dashboard'
      },
    ]
  },
  
  {
    path: '/staff',
    component: Layout,
    redirect: '/staff/staff',
    name: 'staff',
    meta: {title: '员工管理', icon: 'example'},
    children: [
      {
        path: '/staff/staff', name: '员工管理', component: _import('staff/staff'), menu: 'staff',
        children:[
          {
            path: 'test', name: '人员管理', component: _import('staff/test'), meta: {title: '人员管理', icon: 'user'}, menu: 'staff',
          }
          
        ]
      },

      
    ]
  },
  {
    path: '/department',
    component: Layout,
    redirect: '/department/department',

    children: [
      {
        path: 'department',
        name: '部门管理',
        component: _import('department/department'),
        meta: {title: '部门管理', icon: 'example'},
        menu: 'department'
      },
    ]
  },
  {
    path: '/position',
    component: Layout,
    redirect: '/position/position',
    children: [
      {
        path: 'position',
        name: '岗位管理',
        component: _import('position/position'),
        meta: {title: '岗位管理', icon: 'example'},
        menu: 'position'
      },
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/',

    children: [
      {
        path: 'role',
        name: '权限管理',
        component: _import('user/role'),
        meta: {title: '权限管理', icon: 'example'},
        menu: 'role'
      },
    ]
  },
  {
    path: '/parameters',
    component: Layout,
    redirect: '/parameters/parameters',

    children: [
      {
        path: 'role',
        name: '爬虫参数设置',
        component: _import('parameters/parameters'),
        meta: {title: '爬虫参数设置', icon: 'password'},
        menu: 'role'
      },
    ]
  },
  {
    path: '/spider',
    component: Layout,
    redirect: '/spider',
    meta: {title: '爬虫管理', icon: 'password'},
    children: [
      {
        path: 'keyword', name: '关键词管理', component: _import('spider/keyword'), meta: {title: '关键词管理', icon: 'user'}, menu: 'spider',
      },
      {
        path: 'stopword', name: '停用词管理', component: _import('spider/stopword'), meta: {title: '停用词管理', icon: 'user'}, menu: 'spider',
      }
    ]
  },
  {
    path: '/data_dic',
    component: Layout,
    redirect: '/data_dic/data_dic',

    children: [
      {
        path: 'role',
        name: '数据字典',
        component: _import('data_dic/data_dic'),
        meta: {title: '数据字典', icon: 'password'},
        menu: 'role'
      },
    ]
  },

  {path: '*', redirect: '/404', hidden: true}
]
